<?php


namespace app\mingteng\controller;

use think\AjaxPage;
use think\Db;
class Operatelog extends Base
{
    public $listRows = 20;
    public function index(){
        return $this->fetch();
    }

    public function ajax_index(){
        $params = input('post.');
        $page = input('page', '1');

        $where = array();
        if($params['role']){
            $where['s.role'] = $params['role'];
        }
        $count = Db::name('operate_log')->alias('a')
            ->join('user_admin s','s.user_admin_id =a.userId','LEFT')
            ->join('user u','u.userId =a.quUserId','LEFT')
            ->where($where)
            ->count();
        $list = Db::name('operate_log')->alias('a')
            ->join('user_admin s','s.user_admin_id =a.userId','LEFT')
            ->join('user u','u.userId =a.quUserId','LEFT')
            ->where($where)
            ->order('a.id','desc')
            ->field('a.*,s.nickname as admin_nickname,s.role,u.nickName as user_nickname')
            ->page($page, $this->listRows)
            ->select();
        if($list){
            foreach($list as $k=>$v){
                $list[$k]['addTime'] = date('Y-m-d H:i',$v['addTime']);
            }
        }
        $this->assign('list', $list);

        $ajaxPage = new AjaxPage($count, $this->listRows);
        $show = $ajaxPage->show();
        $this->assign('page', $show);

        return $this->fetch();
    }

    public function del(){
        $del_id = input('del_id');

        Db::name('operate_log')->where('id', '=', $del_id)->delete();
        return json(array('code' => 200, 'msg' => '操作成功'));
    }
}